package router

import (
	"gitee.com/gcom/stockdock/core/support"
	"github.com/gorilla/mux"
	"net/http"
)

var Router = mux.NewRouter().StrictSlash(true)
var PubRouter = Router.PathPrefix("/pub").Subrouter()
var ApiRouter = Router.PathPrefix("/api").Subrouter()
var AdminRouter = ApiRouter.PathPrefix("/admin").Subrouter()

func init() {
	PubRouter.Use(support.TraceMiddleware, support.SessionMiddleware)
	ApiRouter.Use(support.TraceMiddleware, support.SessionMiddleware)
	AdminRouter.Use(support.RoleMiddlewareFunc("admin"))
	ApiRouter.Use(support.RoleMiddlewareFunc("admin", "user"))

	fs := http.FileServer(http.Dir("static"))
	Router.PathPrefix("/web").Handler(http.StripPrefix("/web", fs))
}
